import { Express } from 'express'
import { asyncJsonResponse } from '@server/lib/json-response'
import groups_id_get_ts from './groups/[id].get'
import groups_id_put_ts, { bodySchema as groups_id_put_ts_bodySchema } from './groups/[id].put'
import groups_create_post_ts, { bodySchema as groups_create_post_ts_bodySchema } from './groups/create.post'
import groups_list_get_ts from './groups/list.get'
import tags_id_delete_ts from './tags/[id].delete'
import tags_id_get_ts from './tags/[id].get'
import tags_id_put_ts, { bodySchema as tags_id_put_ts_bodySchema } from './tags/[id].put'
import tags_create_post_ts, { bodySchema as tags_create_post_ts_bodySchema } from './tags/create.post'
import tags_list_get_ts from './tags/list.get'
import todos_id_delete_ts from './todos/[id].delete'
import todos_id_get_ts from './todos/[id].get'
import todos_id_put_ts, { bodySchema as todos_id_put_ts_bodySchema } from './todos/[id].put'
import todos_id_restore_post_ts from './todos/[id]/restore.post'
import todos_id_toggle_post_ts from './todos/[id]/toggle.post'
import todos_create_post_ts, { bodySchema as todos_create_post_ts_bodySchema } from './todos/create.post'
import todos_list_get_ts from './todos/list.get'
import todos_sort_post_ts, { bodySchema as todos_sort_post_ts_bodySchema } from './todos/sort.post'
import todos_trash_cleanup_post_ts from './todos/trash/cleanup.post'
import todos_trash_list_get_ts from './todos/trash/list.get'

export function api(app: Express) {
  app.get('/api/groups/:id', asyncJsonResponse(groups_id_get_ts))
  app.put('/api/groups/:id', asyncJsonResponse(groups_id_put_ts, groups_id_put_ts_bodySchema))
  app.post('/api/groups/create', asyncJsonResponse(groups_create_post_ts, groups_create_post_ts_bodySchema))
  app.get('/api/groups/list', asyncJsonResponse(groups_list_get_ts))
  app.delete('/api/tags/:id', asyncJsonResponse(tags_id_delete_ts))
  app.get('/api/tags/:id', asyncJsonResponse(tags_id_get_ts))
  app.put('/api/tags/:id', asyncJsonResponse(tags_id_put_ts, tags_id_put_ts_bodySchema))
  app.post('/api/tags/create', asyncJsonResponse(tags_create_post_ts, tags_create_post_ts_bodySchema))
  app.get('/api/tags/list', asyncJsonResponse(tags_list_get_ts))
  app.delete('/api/todos/:id', asyncJsonResponse(todos_id_delete_ts))
  app.get('/api/todos/:id', asyncJsonResponse(todos_id_get_ts))
  app.put('/api/todos/:id', asyncJsonResponse(todos_id_put_ts, todos_id_put_ts_bodySchema))
  app.post('/api/todos/:id/restore', asyncJsonResponse(todos_id_restore_post_ts))
  app.post('/api/todos/:id/toggle', asyncJsonResponse(todos_id_toggle_post_ts))
  app.post('/api/todos/create', asyncJsonResponse(todos_create_post_ts, todos_create_post_ts_bodySchema))
  app.get('/api/todos/list', asyncJsonResponse(todos_list_get_ts))
  app.post('/api/todos/sort', asyncJsonResponse(todos_sort_post_ts, todos_sort_post_ts_bodySchema))
  app.post('/api/todos/trash/cleanup', asyncJsonResponse(todos_trash_cleanup_post_ts))
  app.get('/api/todos/trash/list', asyncJsonResponse(todos_trash_list_get_ts))
}
